﻿using System.Linq;
using NUnit.Framework;
using Twitter;
using Twitter.Tests;

namespace FriendsNearbyBot.Tests
{
	[TestFixture]
	public class HelpProcessorFixture : TestBase
	{
		[Test]
		public void ShouldSendHelpIfQuestionMarkAndStopDefaultRun()
		{
			MemoryBotClient bot = new MemoryBotClient("fnbtesta");
			MemoryBotClient user = new MemoryBotClient("fnbtestb");
			bot.SetBuddy(user);
			user.SetBuddy(bot);

			HelpProcessor processor = new HelpProcessor(CreateMessageBuilder());

            RunNextProcessor result;

            result = processor.Process(bot, CreateMessage("?", user.ScreenName, bot.ScreenName));

			Assert.AreEqual(RunNextProcessor.No, result);
			Assert.AreEqual(1, user.Messages.GetAll().Count());
            //Assert.AreEqual(Properties.Resources.HelpMessage, 
            //    user.Messages.GetAll().First().Text);
		}

		[Test]
		public void ShouldSendHelpIfHelpWordAndStopDefaultRun()
		{
			MemoryBotClient bot = new MemoryBotClient("fnbtesta");
			MemoryBotClient user = new MemoryBotClient("fnbtestb");
			bot.SetBuddy(user);
			user.SetBuddy(bot);

            HelpProcessor processor = new HelpProcessor(CreateMessageBuilder());

            RunNextProcessor result;

            result = processor.Process(bot, CreateMessage("help", user.ScreenName, bot.ScreenName));

			Assert.AreEqual(RunNextProcessor.No, result);
			Assert.AreEqual(1, user.Messages.GetAll().Count());
            //Assert.AreEqual(Properties.Resources.HelpMessage,
            //    user.Messages.GetAll().First().Text);
		}

		[Test]
		public void ShouldIgnoreOtherMessagesAndLetDefaultRun()
		{
			MemoryBotClient bot = new MemoryBotClient("fnbtesta");
			MemoryBotClient user = new MemoryBotClient("fnbtestb");
			bot.SetBuddy(user);
			user.SetBuddy(bot);

            Message msg = CreateMessage("foo", user.ScreenName, bot.ScreenName);

            HelpProcessor processor = new HelpProcessor(CreateMessageBuilder());
            bool canProc = processor.CanProcess(msg);
			
			Assert.AreEqual(false, canProc);
			Assert.AreEqual(0, user.Messages.GetAll().Count());
		}

        [Test]
        public void DefaultConstructorShouldSplitCommandsPerLine()
        {
            MemoryBotClient bot = new MemoryBotClient("fnbtesta");
            MemoryBotClient user = new MemoryBotClient("fnbtestb");
            bot.SetBuddy(user);
            user.SetBuddy(bot);

            HelpProcessor processor = new HelpProcessor();

            RunNextProcessor result;

            result = processor.Process(bot, CreateMessage("?", user.ScreenName, bot.ScreenName));

            Assert.AreEqual(RunNextProcessor.No, result);
            Assert.Less(1, user.Messages.GetAll().Count());
            AssertString.StartsWith("'", user.Messages.GetAll().Last().Text);
        }
	}
}
